﻿namespace UnitFundProfitability
{
	using System;
	using System.Collections.Generic;
	using System.Windows;
	using System.Windows.Documents;
	using UnitFundProfitability.BusinessLogic;

	/// <summary>
	/// Interaction logic for AddManagementCompany.xaml.
	/// </summary>
	public partial class ManagementCompanies : Window
	{
		#region Constructos
		/// <summary>
		/// Initializes a new instance of the <see cref="ManagementCompanies"/> class.
		/// </summary>
		public ManagementCompanies()
		{
			InitializeComponent();
			AddCompany.Click += new RoutedEventHandler(AddCompany_Click);
			RefreshExistingCompanies();
		}
		#endregion

		#region Methods
		/// <summary>
		/// Refreshes the existing companies.
		/// </summary>
		private void RefreshExistingCompanies()
		{
			IList<ManagementCompany> dataContext = Manager.GetManagementCompanies();
			ExistingCompanies.DataContext = dataContext;
		}

		/// <summary>
		/// Handles the Click event of the AddCompany control.
		/// </summary>
		/// <param name="sender">The source of the event.</param>
		/// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
		private void AddCompany_Click(object sender, RoutedEventArgs e)
		{
			ManagementCompany company = new ManagementCompany();
			company.CompanyId = Guid.NewGuid();
			company.CompanyName = CompanyName.Text;
			Manager.AddManagementCompany(company);
			RefreshExistingCompanies();
		}
		#endregion
	}
}